package com.haoxi.gateway.cmppmsg;

import com.haoxi.gateway.util.TypeConvert;

public class CMPP30ConnectRepMessage extends CMPPMessage {

    public CMPP30ConnectRepMessage(byte buf[]) throws IllegalArgumentException {
        super.buf = new byte[25];
        if (buf.length != 25) {
            throw new IllegalArgumentException(
                    "The message that is sent by SMC is wrong");
        } else {
            System.arraycopy(buf, 0, super.buf, 0, buf.length);
            sequence_Id = TypeConvert.byte2int(super.buf, 0);
        }
    }

    public int getStatus() {
        return TypeConvert.byte2int(buf, 4);
    }

    public byte[] getAuthenticatorISMG() {
        byte tmpbuf[] = new byte[16];
        System.arraycopy(buf, 8, tmpbuf, 0, 16);
        return tmpbuf;
    }

    public byte getVersion() {
        return buf[24];
    }

    public String toString() {
        StringBuffer tmpBuf = new StringBuffer("CMPP_Connect_REP: ");
        tmpBuf.append("Sequence_Id=").append(getSequenceId());
        tmpBuf.append(",Status=").append(getStatus());
        tmpBuf.append(",AuthenticatorISMG=").append(
                new String(getAuthenticatorISMG()));

        return tmpBuf.toString();
    }

    public int getCommandId() {
        return CMPPCommon.CMPP_CONNECT_RESP;
    }
}
